package model
{
	import mx.collections.ArrayCollection;

	[Bindable]
	public class Magazine
	{
		private var _title:String;
		private var _publisher:String;
		private var _issueDate:Date;
		private var _coverImage:String;
		private var _pages:ArrayCollection;

		// constructor
		public function Magazine(magazineXml:XML)
		{
			_title = magazineXml.title;
			_publisher = magazineXml.publisher;
			_pages = new ArrayCollection();
			var date:String = magazineXml.date;
			var year:Number = Number(date.substr(0,4));
			var month:Number = Number(date.substr(5,2))-1;
			var day:Number = Number(date.substr(8,2));
			_issueDate = new Date(year,month,day);
			var pagesXML:XMLList = magazineXml.pages.page.*;
			_coverImage = magazineXml.cover;
			_pages.addItem(_coverImage);
			for each(var nextPage:String in pagesXML)
				_pages.addItem(nextPage);
		}
		
		// getters
		public function get title():String
		{
			return _title;
		}
		
		public function get publisher():String
		{
			return _publisher;
		}
		
		public function get issueDate():String
		{
			return _issueDate.toDateString();
		}
		
		public function get pages():ArrayCollection
		{
			return _pages;
		}
		
		public function get coverImage():String
		{
			return _coverImage;
		}
		
		public function toString():String
		{
			return title+"\n"+"Publisher: " + publisher+"\n"+ issueDate;
		}
	}
}